$NetBSD$

# Respect the environment
--- samtools-1.3/Makefile.orig	2016-03-07 07:49:06 UTC
+++ samtools-1.3/Makefile
@@ -21,10 +21,10 @@
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 # DEALINGS IN THE SOFTWARE.
 
-CC       = gcc
-CPPFLAGS =
-CFLAGS   = -g -Wall -O2
-LDFLAGS  =
+CC       ?= gcc
+CPPFLAGS ?=
+CFLAGS   ?= -g -Wall -O2
+LDFLAGS  ?=
 LIBS     =
 
 DFLAGS=     -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE
@@ -39,18 +39,18 @@ AOBJS=      bam_index.o bam_plcmd.o sam_
             bam_tview.o bam_tview_curses.o bam_tview_html.o bam_lpileup.o \
             bam_quickcheck.o bam_addrprg.o
 
-prefix      = /usr/local
-exec_prefix = $(prefix)
+PREFIX      ?= /usr/local
+exec_prefix = $(PREFIX)
 bindir      = $(exec_prefix)/bin
 datarootdir = $(prefix)/share
 mandir      = $(datarootdir)/man
 man1dir     = $(mandir)/man1
 
 MKDIR_P = mkdir -p
-INSTALL = install -p
-INSTALL_PROGRAM = $(INSTALL)
-INSTALL_DATA    = $(INSTALL) -m 644
-INSTALL_DIR     = $(MKDIR_P) -m 755
+INSTALL ?= install -p
+INSTALL_PROGRAM ?= $(INSTALL)
+INSTALL_DATA    ?= $(INSTALL) -m 644
+INSTALL_DIR     ?= $(MKDIR_P) -m 755
 
 
 PROGRAMS = samtools
@@ -83,7 +83,8 @@ all: $(PROGRAMS) $(BUILT_MISC_PROGRAMS) 
 # TODO Use configure or htslib.pc to add -rdynamic/-ldl conditionally
 ALL_CPPFLAGS = $(DFLAGS) -I. $(HTSLIB_CPPFLAGS) $(CPPFLAGS)
 ALL_LDFLAGS  = -rdynamic $(HTSLIB_LDFLAGS) $(LDFLAGS)
-ALL_LIBS     = -lz -ldl $(LIBS)
+LDL_LIB      ?= -ldl
+ALL_LIBS     = -lz $(LDL_LIB) $(LIBS)
 
 # Usually config.mk and config.h are generated by running configure
 # or config.status, but if those aren't used create defaults here.
